home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
ubppmpqs.zip
/
ppmp3a.asm
< prev
next >
Wrap
Assembly Source File
|
1992-05-24
|
16KB
|
1,071 lines
;PPMP3a.ASM 2.0
; MACHINE LANGUAGE SUBROUTINES
; FOR PPMPQS
; 1991/92 by YUJI KIDA
;
.386P
code segment use16
assume cs:code,ds:code
INCLUDE UBP.MAC
include ppmp.h
org 100h
start:
JMP START0
align 4
R1_OFF DW ?
R1_SEG DW ?
R2_OFF DW ?
R2_SEG DW ?
X_OFF DW ?
X_SEG DW ?
lpptop dd ?
lppptr dd ?
lppover dd ?
lppcount dd ?
baseXbytes dw ?,0
baseunitbytes dw ?,0
basefileptr dd ?
getreladr dd ?
basehandle dw ?
combihandle dw ?
spmem dw ?
R1_buffer db 4 dup(?)
R2_buffer db 4 dup(?)
X_buffer db maxXbytes dup(?)
bufferptr dw ?
buffer1 db COMBIUNITBYTES dup (?)
buffer2 db COMBIUNITBYTES dup (?)
elimcount dd ?
exchangesw db ?
;* branching
START0:
MOV_AX AR0 ;ARRAY[0] is the command number
MOV BX,offset CMD_TBL
SHL AX,1
ADD BX,AX
JMP CS:[BX]
CMD_TBL:
dw ALLINIT,lppINIT,SETDATA,QSORT,ISORT
dw ELIMINATION,GETRELATION,GETBASES,CLOSEHANDLE
; sweep down the '1'
sweep1:
mov esi,[lpptop]
mov edi,ebx ;input from the main
mov ebx,edi ;last '1'
mov edx,RAMUNITBYTES
sweepLP:
mov eax,1
;find '1' from the top
sweep10:
add esi,edx
cmp eax,fs:[esi]
jne sweep10
;find non '1' from the bottom
sweep20:
sub edi,edx
cmp eax,fs:[edi]
je sweep20
cmp esi,edi
ja sweepret
mov eax,fs:[esi]
xchg eax,fs:[edi]
mov fs:[esi],eax
mov eax,fs:[esi+4]
xchg eax,fs:[edi+4]
mov fs:[esi+4],eax
mov eax,fs:[esi+8]
xchg eax,fs:[edi+8]
mov fs:[esi+8],eax
mov ebx,edi ;last '1'
jmp sweepLP
sweepret:
ret
; check whether the sorting worked well
check:
mov esi,[lpptop]
add esi,12
mov ecx,[lppcount]
dec ecx
check10:
mov eax,fs:[esi]
add esi,12
cmp eax,fs:[esi]
jb check20
dec ecx
jnz check10
clc
ret
check20:
stc
ret
;
; close&delete base- and combination- files
; command#=8
CLOSEHANDLE:
mov ax,cs
mov ds,ax
mov [spmem],sp
mov ah,3eh
mov bx,[basehandle]
int 21h
mov ah,3eh
mov bx,[combihandle]
int 21h
mov ah,41h
mov dx,offset BASEFILENAME
int 21h
mov ah,41h
mov dx,offset COMBIFILENAME
int 21h
mov ax,ss
mov ds,ax
mov es,ax
retf
;
; get combination members
;
GETBASES:
mov ax,cs
mov ds,ax
mov si,[bufferptr]
mov dx,[si]
mov cx,[si+2] ;cx:dx = file ptr
mov ax,dx
or ax,cx
jz getbasesnomore
add si,4
mov [bufferptr],si
mov ah,42h ;move file ptr
mov al,0 ;absolute
mov bx,[basehandle]
int 21h
mov ah,3fh ;read handle
mov dx,offset R1_buffer
mov cx,[baseunitbytes]
int 21h
;set R1,R2,X,F
les di,dword ptr [R1_off]
mov eax,dword ptr [R1_buffer]
mov es:[di+2],eax
mov cx,1
xor ax,ax
or eax,eax
jz short getbase50
inc cx
getbase50:
mov es:[di],cx
les di,dword ptr [R2_off]
mov eax,dword ptr [R2_buffer]
mov es:[di+2],eax
mov cx,1
xor ax,ax
or eax,eax
jz short getbase60
inc cx
getbase60:
mov es:[di],cx
les di,dword ptr [X_off]
mov si,offset X_buffer
mov cx,[si]
and cx,LENMASK
inc cx
rep movsw
getbasesret:
mov ax,ss
mov ds,ax
mov es,ax
retf
getbasesnomore:
les di,dword ptr [R1_off] ;set R1=0
mov word ptr es:[di],0
jmp getbasesret
;
; find relation
; command#=6
GETRELATION:
mov ax,cs
mov ds,ax
mov [spmem],sp
getrelationLP:
mov ebx,[getreladr]
sub ebx,RAMUNITBYTES
mov [getreladr],ebx
cmp dword ptr fs:[ebx],1
jne short nomorerelation
mov eax,fs:[ebx+8]
or eax,eax
jz getrelationLP ;erased data
mov dx,offset buffer1
call getcombi
mov si,offset buffer1
mov [bufferptr],si
getrelation50:
add si,4
cmp dword ptr [si-4],COMBIMASK
jb getrelation50
xor dword ptr [si-4],COMBIMASK
mov dword ptr [si],0 ;end mark
getrelationret:
mov ax,ss
mov ds,ax
retf
nomorerelation:
mov bx,AR0
mov word ptr [bx],0
jmp getrelationret
;
; pseudo-Gaussian elimination
; command#=5
ELIMINATION:
mov ax,cs
mov ds,ax
mov [spmem],sp
elimIN:
mov [exchangesw],0
mov ebx,[lpptop]
add ebx,RAMUNITBYTES
elimLP1:
mov eax,fs:[ebx] ;R
cmp eax,1
je short elimdone
mov esi,ebx
elimLP2:
add esi,RAMUNITBYTES
cmp eax,fs:[esi] ;next R
je short elimmatch
mov ebx,esi
jmp short elimLP1
elimdone:
call sweep1 ;sweep down the '1's (use ebx)
mov eax,ebx
sub eax,[lpptop]
xor edx,edx
mov ecx,RAMUNITBYTES
div ecx
dec eax
mov [elimcount],eax
cmp [exchangesw],0
je elim_alldone
mov ecx,eax
push ecx
mov ebx,1
call qsortmain
pop ecx
; call ssortmain
call isortmain
; call check
jmp elimIN
elim_alldone:
call number_relations
mov eax,[lppover]
mov [getreladr],eax
lds si,dword ptr [X_OFF]
mov [si+2],ecx
xor ax,ax
elim90:
jecxz short elim100
inc ax
shr ecx,16
jmp elim90
elim100:
mov [si],ax
mov ax,ss
mov ds,ax
mov es,ax
retf
elimmatch:
mov [exchangesw],-1
elimmatchLP:
mov ecx,fs:[ebx+4]
mov edx,fs:[esi+4]
cmp ecx,edx
je short fullmatch
; cmp eax,fs:[esi+RAMUNITBYTES]
; jne short halfmatch
; cmp edx,fs:[esi+RAMUNITBYTES+4]
; je short fullmatch_next
halfmatch:
mov fs:[esi],edx ;new R1 = max of old R2 & R2'
mov fs:[esi+4],ecx ;new R2 = min of old R2 & R2'
jmp short rewritecombi
fullmatch:
mov dword ptr fs:[esi],1 ;new R1 = 1
mov dword ptr fs:[esi+4],1 ;new R2 = 1
rewritecombi:
push ebx ;/*
mov eax,fs:[esi+8]
mov edx,offset buffer1
call getcombi
pop ebx ;*/
push ebx ;/*
mov eax,fs:[ebx+8]
mov edx,offset buffer2
call getcombi
push si ;/**
call linkcombi
pop si ;**/
sub di,offset buffer1
cmp di,COMBIUNITBYTES
ja short toolonglink
call putnewcombi
mov fs:[esi+8],eax ;new file ptr
pop ebx ;*/
jmp elimLP2
fullmatch_next:
push ebx ;/*
mov dword ptr fs:[esi],1 ;new R1 = 1
mov dword ptr fs:[esi+4],1 ;new R2 = 1
mov eax,fs:[esi+8]
mov edx,offset buffer1
call getcombi
mov eax,fs:[esi+RAMUNITBYTES+8]
mov edx,offset buffer2
call getcombi
push si ;/**
call linkcombi
pop si ;**/
sub di,offset buffer1
cmp di,COMBIUNITBYTES
ja short toolonglink
call putnewcombi
mov fs:[esi+8],eax ;new ptr
pop ebx ;*/
mov eax,fs:[ebx]
add esi,RAMUNITBYTES
jmp elimmatchLP
toolonglink:
mov dword ptr fs:[esi],1 ;erased marks
mov dword ptr fs:[esi+4],1 ;
mov dword ptr fs:[esi+8],0 ;
pop ebx
jmp elimLP2
getcombi:
cmp eax,COMBIMASK
jae short getcombidirect
push dx
mov dx,ax
shr eax,16
mov cx,ax ;cx:dx = file ptr
mov ah,42h ;move pointer
mov al,0 ;absolute
mov bx,[combihandle]
int 21h
pop dx
mov ah,3fh ;read handle
mov cx,COMBIUNITBYTES
int 21h
ret
getcombidirect:
mov bx,dx
mov [bx],eax
ret
linkcombi:
mov di,offset buffer1 - 4
mov si,offset buffer2
linkcombi10:
add di,4
cmp dword ptr [di],COMBIMASK
jb linkcombi10
xor dword ptr [di],COMBIMASK
add di,4
linkcombi20:
mov eax,[si]
mov [di],eax
add si,4
add di,4
cmp eax,COMBIMASK
jb linkcombi20
ret ;di = next of endmark
putnewcombi:
push di ;/* size
mov ah,42h ;move pointer
mov al,2 ;to the end
mov bx,[combihandle]
xor cx,cx
xor dx,dx
int 21h
pop cx ;*/
push dx ;/* dx:ax = new ptr
push ax ;/**
mov dx,offset buffer1
mov ah,40h ;write handle
int 21h
cmp ax,cx
jne short combidiskfull
pop eax ;**/ */ eax = new ptr
clc
ret
writeinitcombi:
mov dx,offset buffer1
mov ah,40h ;write handle
mov bx,[combihandle]
mov cx,4
int 21h
cmp ax,cx
jne short combidiskfull
clc
ret
combidiskfull:
mov word ptr ds:[AR0],8001h
mov sp,cs:[spmem]
mov ax,ss
mov ds,ax
mov es,ax
retf
number_relations:
mov eax,[elimcount]
mov edx,RAMUNITBYTES
mul edx
add eax,[lpptop]
mov ebx,eax
xor ecx,ecx
numrel10:
add ebx,RAMUNITBYTES
cmp ebx,[lppover]
jae short numrel100
cmp dword ptr fs:[ebx+8],0
je numrel10 ;erased data
inc ecx
jmp numrel10
numrel100:
mov eax,ecx
ret ;eax = ecx = result
;
; insertion sort wrt R1 as 1stKey and R2 as 2ndKey
; command#=4
copySIDI macro
mov eax,fs:[esi] ;12 bytes
mov fs:[edi],eax
mov eax,fs:[esi+4]
mov fs:[edi+4],eax
mov eax,fs:[e